// models.go

package main

import (
	"time"
)

func createNewLog(clientID string, connectedAt time.Time) ConnectionLog {
	return ConnectionLog{
		ClientID:           clientID,
		LastAtConnect:      connectedAt,
		SecondAtConnect:    defaultTime,
		ThirdAtConnect:     defaultTime,
		LastAtDisconnect:   defaultTime,
		SecondAtDisconnect: defaultTime,
		ThirdAtDisconnect:  defaultTime,
	}
}

func updateConnectionLog(log *ConnectionLog, connectedAt time.Time) {
	log.ThirdAtConnect = log.SecondAtConnect
	log.SecondAtConnect = log.LastAtConnect
	log.LastAtConnect = connectedAt
}

func updateDisconnectionLog(log *ConnectionLog, disconnectedAt time.Time) {
	log.ThirdAtDisconnect = log.SecondAtDisconnect
	log.SecondAtDisconnect = log.LastAtDisconnect
	log.LastAtDisconnect = disconnectedAt
}

type ConnectionLog struct {
	ID                 uint `gorm:"primaryKey"`
	ClientID           string
	LastAtConnect      time.Time
	SecondAtConnect    time.Time
	ThirdAtConnect     time.Time
	LastAtDisconnect   time.Time
	SecondAtDisconnect time.Time
	ThirdAtDisconnect  time.Time
}

type SubscribeList struct {
	ID       u0.int `gorm:"primaryKey"`
	ClientID string
	Topic    string
	LastTime time.Time
}

var defaultTime = time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)
